package com.lgt_enterprise_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lgt_enterprise_android.R;
import com.lgt_enterprise_android.base.MyBaseAdapter;
import com.lgt_enterprise_android.utils.CommonUtil;
import com.lgt_enterprise_android.utils.StringUtil;

public class MyWorkorsAdapter extends MyBaseAdapter {

    public MyWorkorsAdapter(Context _mContext, JSONArray _mArray){
        super(_mContext,_mArray);
    }

    public String getStaffIdByPos(int pos){
        JSONObject jsonObject=mArray.getJSONObject(pos);
        return jsonObject.getJSONObject("workerInfo").getString("id");
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_staff, null);
            holder.txtName = (TextView) convertView.findViewById(R.id.txt_name);
            holder.txtProp = (TextView) convertView.findViewById(R.id.txt_prop);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        JSONObject jsonObject=mArray.getJSONObject(pos);

        JSONObject staffJsonObj=jsonObject.getJSONObject("workerInfo");

        holder.txtName.setText(staffJsonObj.getString("empName"));

        String genderStr= CommonUtil.getGenderStr(staffJsonObj.getIntValue("gender"));
//        String goodAT="";
//        JSONArray jsonArray=jsonObject.getJSONArray("workerTagDOList");

//        for(int i=0;i<jsonArray.size();i++){
//            JSONObject jo=jsonArray.getJSONObject(i);
//            goodAT+=jo.getString("tagContent")+",";
//        }
//
//        if(goodAT.length()>0){
//            goodAT=goodAT.substring(0,goodAT.length()-1);
//        }

        String age=staffJsonObj.getString("age");
        if(StringUtil.isEmpty(age)){
            age="";
        }else{
            age+="/";
        }

        holder.txtProp.setText(age+genderStr);
        return convertView;
    }

    public class ViewHolder {
        public TextView txtName;
        public TextView txtProp;
    }
}
